package com.health.mapp.impl;

import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger;

import com.health.db.model.VoiceOnDemond;
import com.health.db.model.VoiceOnDemondListExample;
import com.health.db.service.user.IVoiceOnDemondListService;
import com.health.db.service.user.IVoiceOnDemondService;
import com.health.mapp.bean.Header;
import com.health.mapp.bean.QueryVoiceOnDemondListReq;
import com.health.mapp.bean.QueryVoiceOnDemondListResp;
import com.health.mapp.utils.Response;
import com.health.mapp.utils.ResultCode;
/**
 *专家讲堂
 *每日专家语音小课堂。
 *每月一次专家健康讲座 增加与健康专家交流机会、会员免费参与
 * @author YuChong
 *
 */
public class QueryVoiceOnDemondListImpl implements ActionInterface {

	private static Logger logger = Logger.getLogger(QueryVoiceOnDemondListImpl.class);
	
	private IVoiceOnDemondListService voiceOnDemondListService;
	
	private IVoiceOnDemondService voiceOnDemondService;
	
	@Override
	public Response execute(Header header, Object reqBean) throws Exception {
	 
		
		QueryVoiceOnDemondListReq req = (QueryVoiceOnDemondListReq) reqBean;
		QueryVoiceOnDemondListResp _resp = new QueryVoiceOnDemondListResp();
		
		VoiceOnDemondListExample example = new VoiceOnDemondListExample();
		Integer pageNo = req.getPageNo();
	    Integer pageNum = req.getPageNum();
	    Long recId = null;
        //设置分页查询
        if(null!=pageNo&&null!=pageNum){
        	example.setOffset((pageNo.intValue()-1)*pageNum.intValue());
        	example.setPageSize(pageNum.intValue());
        	example.setIsUsedFlag((short)1);
        	example.setIsIssueFlag((short)1);
		}else{
			_resp.setErrorCode(ResultCode.OPERATION_LAKE_PARAMETER_ERROR);
			_resp.setErrorMsg(ResultCode.OPERATION_LAKE_PARAMETER_ERROR_NOTE);
			return _resp;
		}
        
        if (StringUtils.isNotEmpty(req.getRecid())) {
        	recId = Long.valueOf(req.getRecid());
        }else{
        	List<VoiceOnDemond> voiceOnDemonds =voiceOnDemondService.selectByExample(null);
        	
        	if (voiceOnDemonds.size()==1) {
        		recId = voiceOnDemonds.get(0).getRecid();
			}else{
				_resp.setErrorCode(ResultCode.OPERATION_LAKE_PARAMETER_ERROR);
				_resp.setErrorMsg(ResultCode.OPERATION_LAKE_PARAMETER_ERROR_NOTE);
				return _resp;
			}
        }
        
        example.setVoiceOnDemondId(recId);
    	
        if (pageNo==1) {
        	_resp.setVoiceOnDemond(voiceOnDemondService.selectByPrimaryKey(recId));
		}
        
		_resp.setVoiceOnDemondList( voiceOnDemondListService.selectByExample(example));
		_resp.setPageNo(pageNo);
		_resp.setPageNum(pageNum);
		
		return _resp;
	}
	public IVoiceOnDemondListService getVoiceOnDemondListService() {
		return voiceOnDemondListService;
	}
	public void setVoiceOnDemondListService(
			IVoiceOnDemondListService voiceOnDemondListService) {
		this.voiceOnDemondListService = voiceOnDemondListService;
	}
	public IVoiceOnDemondService getVoiceOnDemondService() {
		return voiceOnDemondService;
	}
	public void setVoiceOnDemondService(IVoiceOnDemondService voiceOnDemondService) {
		this.voiceOnDemondService = voiceOnDemondService;
	}
	
}

